package com.dykj.fireFighting.web.base.app;

import com.dykj.fireFighting.api.base.fireGroup.dto.FireGroupAndDevDto;
import com.dykj.fireFighting.api.base.fireGroup.entity.FireGroupAndDev;
import com.dykj.fireFighting.api.base.fireGroup.service.IFireGroupAndDevService;
import com.dykj.fireFighting.api.base.news.dto.NoticeNewsDto;
import com.dykj.fireFighting.api.base.news.entity.NoticeNews;
import com.dykj.fireFighting.api.base.news.service.INoticeNewsService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.exception.BaseException;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 消息通知（3.2版本新增）接口
 *
 * @Author JacksonTu
 * @Date  2021-08-24 15:19:34
 */
@Slf4j
@Api(value = "消防群组", tags = {"消防群组"})
@RestController
@RequestMapping("app/fireGroup")
public class FireGroupAndDevController {

    @DubboReference
    private IFireGroupAndDevService fireGroupAndDevService;

    /**
     * 获取单位id
     *
     * @return String
     */
    public String getEnterpriseId() {
        try {
            return Long.toString(ShiroUtil.getUser().getEnterpriseId());
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw new BaseException("请登录系统");
        }
    }

    /**
     * 获取用户名称
     *
     * @return String
     */
    public String getName() {
        try {
            return ShiroUtil.getUser().getName();
        } catch (NullPointerException e) {
            e.printStackTrace();
            throw new BaseException("请登录系统");
        }
    }


    /**
     * 消息通知（3.2版本新增）列表
     *
     * @return
     */
    @AutoLog(value = "消防群组")
    @ApiOperation(value = "消防群组列表", notes = "消防群组列表")
    @GetMapping("/list")
    public CommonResult<List<FireGroupAndDev>> treeGrid(FireGroupAndDevDto commonDto) {
        commonDto.setUnitId(getEnterpriseId());
        int enterpriseType=ShiroUtil.getUser().getEnterpriseType();//单位类型(社会单位:0，维保单位:1，监控中心:2)
        List<FireGroupAndDev> list = fireGroupAndDevService.getList(commonDto,enterpriseType,getEnterpriseId());
        return CommonResult.success(list);
    }
}
